/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : SimpleProcessAction.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Dec 4, 2008       Raghu Sarraff			       Created
 */
package lwf.web.struts.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lwf.handler.SimpleProcessHandler;
import lwf.web.struts.action.form.WorkSheetForm;

import net.lwf.web.constant.IPageTitle;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


/**
 * Type the class description here
 *  
 */
public class SimpleProcessAction extends WorkSheetAction {
	private String pageTitle;
	
	public ActionForward home(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		WorkSheetForm wform = (WorkSheetForm) form;
		String path = mapping.getPath();

		if(mapping.getPath().equalsIgnoreCase("/findevenodd")) {
			//wform.setTitle("Even and Odd Numbers");
			this.pageTitle = IPageTitle.EVEN_ODD_NUMBERS;
			wform.setFormaction(path);
		}
		if(mapping.getPath().equalsIgnoreCase("/findmissingletter")) {
			//wform.setTitle("Find Missing Letter in a word");
			this.pageTitle = IPageTitle.FIND_MISSING_LETTER;
			wform.setFormaction(path);
		}
		return mapping.findForward("success");
	} //home	
	
	public ActionForward selectoperation(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
        String questiontype = request.getParameter("qtype");
		SimpleProcessHandler sumdetails = new SimpleProcessHandler(questiontype);
		//set to session
		setSumData(request, sumdetails);
		// Write the HTML to response
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println(sumdetails.getDisplayFormatter().getFormattedQuestion());
		//the html string value will be retrieved as 'req.responseText'
		// and will be displayed using the element id = questionblock
		out.flush();

		return null; // Not forwarding to anywhere, response is fully-cooked
	}
	
	@Override
	public String getPageTitle() {
		return this.pageTitle;
	}

	@Override
	public String getMainTitle() {
		return null;
	}

	@Override
	public String getPdfLink() {
		return null;
	}

	@Override
	public String getQuizLink() {
		return null;
	}
}

